package com.tjmc.tiomsresource.parser;

import com.tjmc.tiomscore.model.TranPtnHwTdm;
import org.dom4j.Element;
import org.springframework.stereotype.Component;

import java.util.ArrayList;
import java.util.List;

/**
 * @author Luc
 * @version 1.0
 * @date 2020-05-11 17:56
 */

@Component("cmTdmParser")
public class CMTdmParser extends AbstractParser<TranPtnHwTdm> {

    public List<TranPtnHwTdm> parseXML(List<Element> objectElements) {
        if(null == objectElements || objectElements.size() == 0) {
            return null;
        }
        List<TranPtnHwTdm> tranPtnHwTdmList = new ArrayList<>();
        int j = 0;
        for(Element objectElement : objectElements) {
            if(++j == PRINT_LOG_SPLIT || j == objectElements.size()) {
                logger.info("解析：" + j + ", size=" + objectElements.size());
            }
            String rmUID = objectElement.attributeValue("rmUID");
            TranPtnHwTdm tranPtnHwTdm = new TranPtnHwTdm();
            tranPtnHwTdm.setRmuid(rmUID);
            List<Element> vElements = objectElement.elements("V");
            if(null == vElements || vElements.size() == 0) {
                continue;
            }
            for(Element vElement : vElements) {
                int i = Integer.parseInt(vElement.attributeValue("i"));
                switch(i) {
                    case 1:
                        tranPtnHwTdm.setNativename(vElement.getTextTrim());
                        break;
                    case 2:
                        tranPtnHwTdm.setRate(vElement.getTextTrim());
                        break;
                    case 3:
                        tranPtnHwTdm.setDirection(vElement.getTextTrim());
                        break;
                    case 4:
                        tranPtnHwTdm.setActivestate(vElement.getTextTrim());
                        break;
                    case 5:
                        tranPtnHwTdm.setOwner(vElement.getTextTrim());
                        break;
                    case 6:
                        tranPtnHwTdm.setOwnesservicetype(vElement.getTextTrim());
                        break;
                    case 7:
                        tranPtnHwTdm.setAend1tprmuid(vElement.getTextTrim());
                        break;
                    case 8:
                        tranPtnHwTdm.setAend1nermuid(vElement.getTextTrim());
                        break;
                    case 9:
                        tranPtnHwTdm.setAend1portrmuid(vElement.getTextTrim());
                        break;
                    case 10:
                        tranPtnHwTdm.setAend1ctpid(vElement.getTextTrim());
                        break;
                    case 11:
                        tranPtnHwTdm.setAend2tprmuid(vElement.getTextTrim());
                        break;
                    case 12:
                        tranPtnHwTdm.setAend2nermuid(vElement.getTextTrim());
                        break;
                    case 13:
                        tranPtnHwTdm.setAend2portrmuid(vElement.getTextTrim());
                        break;
                    case 14:
                        tranPtnHwTdm.setAend2ctpid(vElement.getTextTrim());
                        break;
                    case 15:
                        tranPtnHwTdm.setZend1tprmuid(vElement.getTextTrim());
                        break;
                    case 16:
                        tranPtnHwTdm.setZend1nermuid(vElement.getTextTrim());
                        break;
                    case 17:
                        tranPtnHwTdm.setZend1portrmuid(vElement.getTextTrim());
                        break;
                    case 18:
                        tranPtnHwTdm.setZend1ctpid(vElement.getTextTrim());
                        break;
                    case 19:
                        tranPtnHwTdm.setZend2tprmuid(vElement.getTextTrim());
                        break;
                    case 20:
                        tranPtnHwTdm.setZend2nermuid(vElement.getTextTrim());
                        break;
                    case 21:
                        tranPtnHwTdm.setZend2portrmuid(vElement.getTextTrim());
                        break;
                    case 22:
                        tranPtnHwTdm.setZend2ctpid(vElement.getTextTrim());
                        break;
                    case 23:
                        tranPtnHwTdm.setPw1rmuid(vElement.getTextTrim());
                        break;
                    case 24:
                        tranPtnHwTdm.setPw2rmuid(vElement.getTextTrim());
                        break;
                }
            }
            tranPtnHwTdmList.add(tranPtnHwTdm);
        }
        return tranPtnHwTdmList.size()==0?null:tranPtnHwTdmList;
    }
}
